package org.third.integration.hibernate;

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DbMySQLTest extends DbTest {

    public static void main(String[] args) {
        new DbMySQLTest().testDatabase();
        if (!(null instanceof Boolean)) {
            System.out.println(3);
        }
    }

    @Test
    public void testDatabase() {
        Connection conn = null;
        try {
            // conn = DriverManager.getConnection("jdbc:sqlserver://15.119.81.210\\SAML:1433;DatabaseName=idm_gongyo2",
            // "gongyo", "gongyo");
            conn = DriverManager.getConnection("jdbc:mysql://15.119.81.210:3306/idm_gongyo3", "root", "admin");
            printConnection(conn);
            Statement stmt = conn.createStatement();

            String test1 = "上海組織噂閏云ボ厭ポ院ｱ걒걓걕乗乕哴哵厈厊厎";

            // stmt.execute(
            // "insert into aa_test(name) values('" + (new String("上海組織噂閏云ボ厭ポ院ｱ걒걓걕乗乕哴哵厈厊厎汉".getBytes("gbk"),
            // "ISO-8859-1")) + "')");
            // stmt.execute(
            // "insert into aa_test(name) values('" + (new String("上海組織噂閏云ボ厭ポ院ｱ걒걓걕乗乕哴哵厈厊厎汉".getBytes("utf-8"),
            // "ISO-8859-1")) + "')");
            // stmt.execute("insert into aa_test(name) values(N\'hello\')");
            stmt.execute("insert into aa_test(name) values(N\'" + test1 + "\')");
            // ResultSet rs = stmt.executeQuery(
            // "select * from aa_test where name like '" + new String("上海".getBytes("GBK"), "iso-8859-1") + "%'");
            ResultSet rs = stmt.executeQuery("select * from aa_test where name like '上海%'");
            while (rs.next()) {
                System.out.println(rs.getString(1));
                // System.out.println(new String(rs.getString(1).getBytes("iso-8859-1"), "gbk"));
                // System.out.println(new String(rs.getString(1).getBytes("iso-8859-1"), "utf-8"));
                // System.out.println(new String(rs.getString(1).getBytes("iso-8859-1"),"iso-8859-1"));
                // System.out.println(new String(new
                // String(rs.getString(1).getBytes("iso-8859-1"),"iso-8859-1").getBytes("iso-8859-1"), "utf-8"));
                // System.out.println(new String(new
                // String(rs.getString(1).getBytes("iso-8859-1")).getBytes("iso-8859-1"),"utf-8"));
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
